package com.mrper.jnindk;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class PageJumpActivity extends AppCompatActivity {

    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_page_jump);
        webView = (WebView)findViewById(R.id.webView);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setBuiltInZoomControls(false);
        webView.getSettings().setSupportZoom(false);
        webView.getSettings().setDisplayZoomControls(false);
        webView.addJavascriptInterface(new JsInterface(),"JsInterface");
        webView.setWebChromeClient(new BaseWebChromeClient());
        webView.setWebViewClient(new BaseWebViewClient());
        webView.loadUrl("http://mgtest.nurenhua.net/inside-api/js-scheme");
    }


    class JsInterface{

        @JavascriptInterface
        public void CallJumpMethod(String event,String type,String params){
            System.out.println(String.format("event = %s, type = %s, params = %s",event,type,params));
        }

    }


    //#####################################################################################
    //##                                                                                ###
    //##             针对WebChromeClient和WebViewClient所做的类的实现,                     ###
    //##             直接调用Activity类中定义的响应方法                                     ###
    //##                                                                                ###
    //#####################################################################################

    class BaseWebChromeClient extends WebChromeClient {

        @Override
        public void onReceivedTitle(WebView view, String title) {
        }

        @Override
        public void onProgressChanged(WebView view, int newProgress) {
        }





    }

    class BaseWebViewClient extends WebViewClient{

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return super.shouldOverrideUrlLoading(view, url);
        }
    }

}
